//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "FdSimpleExtOUJumpSwingEngine.h"
using namespace Cephei::QL::Experimental::Finitedifferences;
#include <gen/QL/Experimental/Processes/ExtOUWithJumpsProcess.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
#include <gen/QL/Methods/Finitedifferences/Solvers/FdmSchemeDesc.h>
#include <gen/QL/PricingEngine.h>
using namespace Cephei::QL::Experimental::Processes;
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL::Methods::Finitedifferences::Solvers;
using namespace Cephei::QL;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::CFdSimpleExtOUJumpSwingEngine (boost::shared_ptr<QuantLib::FdSimpleExtOUJumpSwingEngine>& childNative, Object^ owner) : CPricingEngine(CFdSimpleExtOUJumpSwingEngine::typeid)
{
#ifdef HANDLE
	_phFdSimpleExtOUJumpSwingEngine = NULL;
#endif
	_ppFdSimpleExtOUJumpSwingEngine = &childNative;
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdSimpleExtOUJumpSwingEngine));
}
Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::CFdSimpleExtOUJumpSwingEngine (QuantLib::FdSimpleExtOUJumpSwingEngine& childNative, Object^ owner) : CPricingEngine(CFdSimpleExtOUJumpSwingEngine::typeid)
{
#ifdef HANDLE
	_phFdSimpleExtOUJumpSwingEngine = NULL;
#endif
	_ppFdSimpleExtOUJumpSwingEngine = new boost::shared_ptr<QuantLib::FdSimpleExtOUJumpSwingEngine> (&childNative);
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdSimpleExtOUJumpSwingEngine));
    _FdSimpleExtOUJumpSwingEngineOwner = owner;
    _PricingEngineOwner = owner;
}

Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::CFdSimpleExtOUJumpSwingEngine (CFdSimpleExtOUJumpSwingEngine^ copy) : CPricingEngine(CFdSimpleExtOUJumpSwingEngine::typeid)
{
#ifdef HANDLE
	_phFdSimpleExtOUJumpSwingEngine = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppFdSimpleExtOUJumpSwingEngine = new boost::shared_ptr<QuantLib::FdSimpleExtOUJumpSwingEngine> (copy->GetShared());
        _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdSimpleExtOUJumpSwingEngine));
    }
}
Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::CFdSimpleExtOUJumpSwingEngine (PLATFORM::Type^ t) : CPricingEngine(CFdSimpleExtOUJumpSwingEngine::typeid)
{
#ifdef HANDLE
	_phFdSimpleExtOUJumpSwingEngine = NULL;
#endif
	if (!t->IsSubclassOf(CFdSimpleExtOUJumpSwingEngine::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::CFdSimpleExtOUJumpSwingEngine (QuantLib::Handle<QuantLib::FdSimpleExtOUJumpSwingEngine>& childNative, Object^ owner)  : CPricingEngine(CFdSimpleExtOUJumpSwingEngine::typeid)
{
	_phFdSimpleExtOUJumpSwingEngine = &childNative;
	_ppFdSimpleExtOUJumpSwingEngine = &static_cast<boost::shared_ptr<QuantLib::FdSimpleExtOUJumpSwingEngine>>(childNative.currentLink());
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdSimpleExtOUJumpSwingEngine));
    _FdSimpleExtOUJumpSwingEngineOwner = owner;
}
Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::CFdSimpleExtOUJumpSwingEngine (QuantLib::Handle<QuantLib::FdSimpleExtOUJumpSwingEngine> childNative)  : CPricingEngine(CFdSimpleExtOUJumpSwingEngine::typeid)
{
	_phFdSimpleExtOUJumpSwingEngine = &childNative;
	_ppFdSimpleExtOUJumpSwingEngine = &static_cast<boost::shared_ptr<QuantLib::FdSimpleExtOUJumpSwingEngine>>(childNative.currentLink());
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdSimpleExtOUJumpSwingEngine));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::CFdSimpleExtOUJumpSwingEngine (QuantLib::FdSimpleExtOUJumpSwingEngine childNative)  : CPricingEngine(CFdSimpleExtOUJumpSwingEngine::typeid)
{
#ifdef HANDLE
	_phFdSimpleExtOUJumpSwingEngine = NULL;
#endif
	_ppFdSimpleExtOUJumpSwingEngine = new boost::shared_ptr<QuantLib::FdSimpleExtOUJumpSwingEngine> (new QuantLib::FdSimpleExtOUJumpSwingEngine (childNative));
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdSimpleExtOUJumpSwingEngine));
}
#endif

Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::~CFdSimpleExtOUJumpSwingEngine ()
{
    if (_ppFdSimpleExtOUJumpSwingEngine != NULL)
    {
	    delete _ppFdSimpleExtOUJumpSwingEngine;
        _ppFdSimpleExtOUJumpSwingEngine = NULL;
    }
}
Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::!CFdSimpleExtOUJumpSwingEngine ()
{
    if (_ppFdSimpleExtOUJumpSwingEngine != NULL)
    {
	    delete _ppFdSimpleExtOUJumpSwingEngine;
    }
}
QuantLib::FdSimpleExtOUJumpSwingEngine& Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::GetReference ()
{
    if (_ppFdSimpleExtOUJumpSwingEngine == NULL) throw REFNEW NativeNullException ();
	return **_ppFdSimpleExtOUJumpSwingEngine;
}
boost::shared_ptr<QuantLib::FdSimpleExtOUJumpSwingEngine>& Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::GetShared ()
{
    if (_ppFdSimpleExtOUJumpSwingEngine == NULL) throw REFNEW NativeNullException ();
	return *_ppFdSimpleExtOUJumpSwingEngine;
}
QuantLib::FdSimpleExtOUJumpSwingEngine* Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::GetPointer ()
{
    if (_ppFdSimpleExtOUJumpSwingEngine == NULL) throw REFNEW NativeNullException ();
	return &**_ppFdSimpleExtOUJumpSwingEngine;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::FdSimpleExtOUJumpSwingEngine>& Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::GetHandle ()
{
	if (_phFdSimpleExtOUJumpSwingEngine == NULL)
	{
		_phFdSimpleExtOUJumpSwingEngine = new Handle<QuantLib::FdSimpleExtOUJumpSwingEngine> (*_ppFdSimpleExtOUJumpSwingEngine);
	}
	return *_phFdSimpleExtOUJumpSwingEngine;
}
#endif
bool Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::HasNative () 
{
	return (_ppFdSimpleExtOUJumpSwingEngine != NULL);
}

Cephei::QL::Experimental::Finitedifferences::IFdSimpleExtOUJumpSwingEngine^ Cephei::QL::Experimental::Finitedifferences::CFdSimpleExtOUJumpSwingEngine::Calculate::get ()
{
    try
    {
    	(*_ppFdSimpleExtOUJumpSwingEngine)->calculate ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

